<template>
  <div class="page-container">
    <a-card :bodyStyle="{ padding: '0' }" :bordered="false">
      <a-tabs v-model:active-key="activeType">
        <a-tab-pane key="1" title="个人信息">
          <card title="个人信息">
            <div class="section-item" style="margin-top: 0">
              <div class="section-item-content">
                <a-descriptions :size="size" :align="{ label: 'right' }">
                  <a-descriptions-item label="姓名">{{ memberDetail.memberName }}</a-descriptions-item>
                  <a-descriptions-item label="手机号">{{ memberDetail.phone }}</a-descriptions-item>
                  <a-descriptions-item label="性别">{{ memberDetail.sexName }}</a-descriptions-item>
                  <a-descriptions-item label="所属企业">{{ memberDetail.clientName }}</a-descriptions-item>
                  <a-descriptions-item label="电子合同认证状态">
                    <div class="status" :class="getClassName(memberDetail)">
                      {{ memberDetail.ecAuthenticationStatusName }}
                    </div>
                    <template v-if="memberDetail.ecAuthenticationStatus === 0">
                      原因: {{ memberDetail.authenticationFailedReason }}
                    </template>
                  </a-descriptions-item>
                </a-descriptions>
              </div>
              <a-divider :margin="16" />
              <div class="section-item-content">
                <a-descriptions :size="size" :align="{ label: 'right' }">
                  <a-descriptions-item label="证件类型">{{ memberDetail.cardTypeName }}</a-descriptions-item>
                  <a-descriptions-item label="驾驶证号">{{ memberDetail.driverNumber }}</a-descriptions-item>
                  <a-descriptions-item>{{ ' ' }}</a-descriptions-item>
                  <a-descriptions-item label="证件号">{{ memberDetail.cardNumber }}</a-descriptions-item>
                  <a-descriptions-item :span="1" label="驾驶证到期日">{{
                    memberDetail.driverLong == 1 ? memberDetail.driverLongName : memberDetail.driverExpireTime
                  }}</a-descriptions-item>
                  <a-descriptions-item>{{ ' ' }}</a-descriptions-item>
                  <a-descriptions-item span="3" label="证件住址">{{ memberDetail.cardAddress }}</a-descriptions-item>
                  <a-descriptions-item label="证件到期日">
                    {{ memberDetail.identityLong == 1 ? memberDetail.identityLongName : memberDetail.identityExpireTime }}
                  </a-descriptions-item>
                  <a-descriptions-item>{{ ' ' }}</a-descriptions-item>
                  <a-descriptions-item>{{ ' ' }}</a-descriptions-item>
                  <a-descriptions-item label="证件照片">
                    <upload-img title="证件正页" v-model="memberDetail.idCardFrontFileId" disabled margin single />
                    <upload-img title="证件副页" v-model="memberDetail.idCardReverseFileId" disabled margin single />
                  </a-descriptions-item>
                  <a-descriptions-item label="驾驶证照片">
                    <upload-img title="驾驶证正页" v-model="memberDetail.driverFrontFileId" disabled margin single />
                    <upload-img title="驾驶证副页" v-model="memberDetail.driverReverseFileId" disabled margin single />
                  </a-descriptions-item>
                </a-descriptions>
              </div>
            </div>
          </card>
          <card title="紧急联系人" :showDivider="false">
            <div class="section-item" style="margin-top: 0">
              <div class="section-item-content">
                <a-descriptions :size="size" :align="{ label: 'right' }">
                  <a-descriptions-item label="姓名">{{ memberDetail.emergencyContactName }}</a-descriptions-item>
                  <a-descriptions-item label="手机号">{{ memberDetail.emergencyContactPhone }}</a-descriptions-item>
                  <a-descriptions-item>{{ ' ' }}</a-descriptions-item>
                </a-descriptions>
              </div>
            </div>
          </card>
        </a-tab-pane>
        <a-tab-pane key="2" title="操作记录">
          <OperateLog :id="routePrams.id" type="19" />
        </a-tab-pane>
      </a-tabs>
    </a-card>
  </div>
</template>

<script setup name="MemberPersonDetail">
  import { ref, nextTick } from 'vue'
  import { useRoute } from 'vue-router'
  import { getDetail } from '@/api/market/member'

  const route = useRoute()
  const routePrams = route.params
  const memberDetail = ref({})

  const getDetails = (id) => {
    getDetail({ id: id }).then((res) => {
      nextTick(() => {
        memberDetail.value = res.result
        memberDetail.value.idCardFrontFileIdList = [res.result.idCardFrontFileId]
        memberDetail.value.idCardReverseFileIdList = [res.result.idCardReverseFileId]
        memberDetail.value.driverFrontFileIdList = [res.result.driverFrontFileId]
        memberDetail.value.driverReverseFileIdList = [res.result.driverReverseFileId]
      })
    })
  }

  const getClassName = (item) => {
    // -1: 未认证 0: 认证失败 1: 认证成功 2: 认证中
    if (item.ecAuthenticationStatus === -1) {
      return 'status-unauth'
    } else if (item.ecAuthenticationStatus === 0) {
      return 'status-failed'
    } else if (item.ecAuthenticationStatus === 1) {
      return 'status-success'
    } else if (item.ecAuthenticationStatus === 2) {
      return 'status-wait'
    }
  }

  console.log(routePrams)
  if (routePrams.id) {
    getDetails(routePrams.id)
  }
</script>

<style lang="less" scoped>
  .section-item {
    .section-item-header {
      color: #1d2129ff;
      font-weight: 500;
    }
    .section-item-content {
      padding: 20px 20px 0 20px;

      .status {
        display: flex;
        justify-content: center;
        align-items: center;
        max-width: 76px;
        height: 20px;
        font-size: 12px;
        font-weight: 500;
        border-radius: 2px 2px 2px 2px;
        border: 1px solid;
        color: rgba(185, 187, 196, 1);
        border-color: rgba(229, 230, 235, 1);
        background-color: rgba(242, 243, 245, 1);

        &.status-unauth {
          color: rgba(185, 187, 196, 1);
          border-color: rgba(229, 230, 235, 1);
          background-color: rgba(242, 243, 245, 1);
        }
        &.status-failed {
          color: rgba(245, 63, 63, 1);
          border-color: rgba(245, 63, 63, 1);
          background-color: rgba(255, 236, 232, 1);
        }
        &.status-success {
          color: rgba(0, 180, 42, 1);
          border-color: rgba(0, 180, 42, 1);
          background-color: rgba(232, 255, 234, 1);
        }
        &.status-wait {
          color: rgba(255, 125, 0, 1);
          border-color: rgba(255, 125, 0, 1);
          background-color: rgba(255, 247, 232, 1);
        }
      }
    }
    .btn {
      margin-left: 16px;
    }
    &.gray {
      background-color: rgba(var(--gray-1), 0.5) !important;
      border-radius: 0px 0px 0px 0px;
      .section-item-content {
        padding: 20px 20px 12px 20px;
      }
    }
  }
  :deep(.upload-margin) {
    margin-right: 10px !important;
  }
  :deep(.arco-descriptions-item-value) {
    padding-right: 0 !important;
  }
  :deep(.arco-descriptions-item-value-block) {
    padding-right: 0 !important;
  }
  :deep(.arco-descriptions-layout-horizontal .arco-descriptions-row .arco-descriptions-item-value) {
    width: 22%;
  }
</style>
